package com.example.libraryapp.network.net;

import com.example.libraryapp.bean.BannerBean;
import com.example.libraryapp.bean.Book;
import com.example.libraryapp.bean.BookBorrow;
import com.example.libraryapp.bean.BookDetail;
import com.example.libraryapp.bean.BookType;
import com.example.libraryapp.bean.User;
import com.example.libraryapp.bean.response.BaseResponse;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;

/**
 * 接口类
 * @author 伍凯铭
 * @since 2020/2/27
 */
public interface ApiService {

    //登录
    @GET("user/login")
    Observable<BaseResponse<User>> login(@Query("sno") String sno, @Query("password") String password);

    //注册
    @POST("user/register")
    Observable<BaseResponse> register(@Body User user);

    //修改用户信息
    @POST("user/update")
    Observable<BaseResponse<User>> updateUser(@Body User user);

    //获取我的收藏
    @GET("favorite/get")
    Observable<BaseResponse<List<Book>>> getFavorite(@Query("userId") long userId);

    //添加收藏
    @FormUrlEncoded
    @POST("favorite/add")
    Observable<BaseResponse> addFavorite(@Field("userId") long userId,@Field("bookId") long bookId);

    //取消收藏
    @FormUrlEncoded
    @POST("favorite/delete")
    Observable<BaseResponse> deleteFavorite(@Field("userId") long userId,@Field("bookId") long bookId);

    //借阅书本
    @FormUrlEncoded
    @POST("borrow/add")
    Observable<BaseResponse> borrowBook(@Field("userId") long userId,@Field("bookId") long bookId);

    //归还书本
    @FormUrlEncoded
    @POST("borrow/return")
    Observable<BaseResponse> returnBook(@Field("userId") long userId,@Field("bookId") long bookId);

    //查看借阅中记录
    @GET("borrow/getNormal")
    Observable<BaseResponse<List<BookBorrow>>> getNormalBorrowBook(@Query("userId") long userId);

    //查看借阅历史
    @GET("borrow/getHistory")
    Observable<BaseResponse<List<BookBorrow>>> getBorrowHistory(@Query("userId") long userId);

    //获取所有图书类型
    @GET("bookType/getAll")
    Observable<BaseResponse<List<BookType>>> getAllBookType();

    //获取所有图书
    @GET("book/getByCondition")
    Observable<BaseResponse<List<Book>>> getByCondition(@Query("condition") String condition);

    //根据类型获取图书
    @GET("book/getByType")
    Observable<BaseResponse<List<Book>>> getBookByType(@Query("typeId") long typeId);

    //根据类型获取图书
    @GET("book/getDetail")
    Observable<BaseResponse<BookDetail>> getDetail(@Query("bookId") long bookId,@Query("userId") long userId);

    //获取Banner
    @GET("banner/getHot")
    Observable<BaseResponse<List<BannerBean>>> getBanner();

}
